﻿@namespace Microsoft.AspNetCore.Components
@inherits ComponentBase
@typeparam Element

<Virtualization Elements="Elements" Initial="Initial" IsReverse=IsReverse Jump="Jump"
                Plus="Plus" RenderElement="RenderElement" BlankHeight="@BlankHeight"
                RenderEmpty=RenderEmpty>
    <RenderComponent>
        @{
            var newRenderInfo = context with
                {
                    RenderContainer = context.RenderContainer with
                    {
                        CSS = context.RenderContainer.CSS + " virtualizationSimpleContainer"
                    }
                };
            var renderContainer = newRenderInfo.RenderContainer;
            var renderElement = newRenderInfo.RenderElement;
        }
        <div class="@renderContainer.CSS" id="@renderContainer.ID" onscroll="@renderContainer.OnScrollScript" @attributes=ContainerAttributes>
            @{
                var renderComponent = new RenderVirtualizationSimpleInfo<Element>()
                {
                    RenderElement = renderElement,
                    GoTop = renderContainer.GoTop,
                    BlankHeight = renderContainer.BlankHeight,
                    RenderEmpty = renderContainer.RenderEmpty,
                    State = renderContainer.State
                };
            }
            @if (RenderComponent is { })
            {
                @RenderComponent(renderComponent)
            }
            else
            {
                switch (renderComponent.State)
                {
                    case RenderVirtualizationState.HasElements:
                        @foreach (var item in renderElement)
                        {
                            @item
                        }
                        <div style="@renderComponent.BlankHeight" />
                        break;
                    case RenderVirtualizationState.NotElements:
                        @renderComponent.RenderEmpty
                        break;
                }
            }
        </div>
    </RenderComponent>
</Virtualization>